package com.cw.lang.common.framework.config;

import java.util.TimeZone;

import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.cw.lang.common.utils.DateUtil;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * @author chenw
 * @version $$Id: JacksonConfiguration.java, v 0.1 2019/2/27 8:23 PM chenw Exp $$
 */
@Configuration
public class JacksonConfiguration {

    /**
     * 如果controller的返回对象为一个空对象（不是void），jackson默认是不支持的，需要开启
     *
     * @return {@link Jackson2ObjectMapperBuilderCustomizer}
     */
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer customizer() {
        return jacksonObjectMapperBuilder -> jacksonObjectMapperBuilder.featuresToDisable(
            SerializationFeature.FAIL_ON_EMPTY_BEANS, MapperFeature.AUTO_DETECT_IS_GETTERS)
            .timeZone(TimeZone.getDefault())
            .dateFormat(DateUtil.getDateFormat(DateUtil.DATETIME_FORMAT_1));
    }
}
